<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Jobs\SendEmailJob;
use App\Model\Cates;

/**
 * Description of BookedController
 */
class BookedController extends Controller {

    public function queueSend()
    {
        //邮件发送demo数据
        // 推送到任务队列
//        dispatch(new SendEmailJob('1090300992@qq.com','您好呀！！邓少！！！','网易云公司'));
        $cates = Cates::where(['cate_name'=>'前端开发177140'])->get()->toArray();
//        $cates = Cates::count();
//
        return $cates;

    }
    // 测速mysql响应
    public function updateMysql()
    {
        // chunk方式，执行效率较低
//        $cate = Cates::chunk(100,function ($cates){
//            foreach ($cates as $cate){
//                // 修改前一百的mysql
//                $cate->update(['cate_image'=>'']);
//            }
//        });
        //
        $cate = Cates::where('cate_title', '前端')->select(array('cate_image', 'cate_id'))->chunkById(1000, function ($cates){
            // 业务处理
            foreach ($cates as $cate){
                // 修改前一百的mysql
                $cate->update(['cate_image'=>'/unload/image/333.png']);
            }
        },'created_at');
//        $data = [
//            'code'=>200,
//            'message'=>'更新成功',
//            'data'=>$cate,
//        ];
        return '更新成功';
    }

    public function createMysql()
    {
        $cate = Cates::chunk(100,function ($cates){
            foreach ($cates as $cate){
                // 批量添加一百的mysql
                $cate->create([
                    'cate_name'=>'前端开发',
                    'cate_title'=>'前端',
                    'cate_order'=>'1',
                    'cate_pid'=>'2',
                    'cate_image'=>'/unload/image/111.png'
                ]);
            }
        });
//        $data = [
//            'code'=>200,
//            'message'=>'添加成功',
//            'data'=>$cate,
//        ];
//        return $data;
    }
}


